package org.lyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.lyg.dao.ICommentMapper;
import org.lyg.domain.Comment;
import org.lyg.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("commentService")
public class CommentServiceImpl implements ICommentService {
    @Autowired
    ICommentMapper commentMapper;

    @Override
    public PageInfo<Comment> list(int page, int size) {
        PageHelper.startPage(page, size);
        List<Comment> commentList = commentMapper.list();
        return new PageInfo<>(commentList);
    }

    @Override
    public PageInfo<Comment> getCommentByBlogId(int id, int page, int size) {
        PageHelper.startPage(page, size);
        List<Comment> commentList = commentMapper.getCommentByBlogId(id);
        return new PageInfo<>(commentList);
    }

    @Override
    public PageInfo<Comment> getCommentByUserId(int id, int page, int size) {
        PageHelper.startPage(page, size);
        List<Comment> commentList = commentMapper.getCommentByUserId(id);
        return new PageInfo<>(commentList);
    }

    @Override
    public boolean save(Comment comment) {
        int result = commentMapper.save(comment);
        return result>0;
    }
}
